/*     */ package net.sourceforge.appgen.model;
/*     */ 
/*     */ import java.io.Serializable;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Date;
/*     */ import java.util.List;
/*     */ import net.sourceforge.appgen.converter.FirstCharacterUpperCaseConverter;
/*     */ import net.sourceforge.appgen.converter.StringConverter;
/*     */ import net.sourceforge.appgen.util.ConventionUtils;
/*     */ import net.sourceforge.appgen.util.FileUtils;
/*     */ 
/*     */ public class FormController
/*     */   implements Serializable
/*     */ {
/*     */   private static final long serialVersionUID = 1L;
/*  37 */   private static final StringConverter firstCharacterUpperCaseConverter = new FirstCharacterUpperCaseConverter();
/*     */   private Entity entity;
/*     */ 
/*     */   public FormController(Entity entity)
/*     */   {
/*  42 */     this.entity = entity;
/*     */   }
/*     */ 
/*     */   public String getClassName() {
/*  46 */     return this.entity.getClassName() + "FormController";
/*     */   }
/*     */ 
/*     */   public String getFullPackageName() {
/*  50 */     return this.entity.getPackageName() + ".web.controller";
/*     */   }
/*     */ 
/*     */   public String getSuperClassName() {
/*  54 */     return "SimpleFormController";
/*     */   }
/*     */ 
/*     */   public String getSuperClassFullPackageName() {
/*  58 */     return "org.springframework.web.servlet.mvc";
/*     */   }
/*     */ 
/*     */   public List<String> getImportClassNameList() {
/*  62 */     List list = new ArrayList();
/*     */ 
/*  64 */     list.add(getSuperClassFullPackageName() + "." + getSuperClassName());
/*     */ 
/*  66 */     list.add(this.entity.getFullPackageName() + "." + this.entity.getClassName());
/*     */ 
/*  68 */     Criteria criteria = new Criteria(this.entity);
/*  69 */     list.add(criteria.getFullPackageName() + "." + criteria.getClassName());
/*     */ 
/*  71 */     Service service = new Service(this.entity);
/*  72 */     list.add(service.getInterfaceFullPackageName() + "." + service.getInterfaceName());
/*     */ 
/*  74 */     list.add("javax.servlet.http.HttpServletRequest");
/*  75 */     list.add("javax.servlet.http.HttpServletResponse");
/*  76 */     list.add("org.springframework.web.servlet.ModelAndView");
/*  77 */     list.add("org.springframework.web.bind.ServletRequestUtils");
/*  78 */     list.add("org.springframework.web.bind.ServletRequestDataBinder");
/*  79 */     list.add("java.util.Map");
/*  80 */     list.add("java.util.LinkedHashMap");
/*  81 */     list.add("org.springframework.validation.BindException");
/*     */ 
/*  83 */     if (isCustomDateEditorRequired()) {
/*  84 */       list.add("java.util.Date");
/*  85 */       list.add("java.text.SimpleDateFormat");
/*  86 */       list.add("org.springframework.beans.propertyeditors.CustomDateEditor");
/*     */     }
/*     */ 
/*  89 */     if (this.entity.getPrimaryKeyFieldList() != null) {
/*  90 */       for (Field field : this.entity.getPrimaryKeyFieldList()) {
/*  91 */         if ((!field.isCreate()) || (field.getFieldType().indexOf('.') <= 0) || 
/*  92 */           (field.getFieldType().equals("java.lang." + field.getSimpleFieldType())) || 
/*  93 */           (list.contains(field.getFieldType()))) continue;
/*  94 */         list.add(field.getFieldType());
/*     */       }
/*     */ 
/*     */     }
/*     */ 
/* 101 */     for (Field field : this.entity.getFieldList()) {
/* 102 */       if ((field.isCreate()) && ("AttachFile".equals(field.getFieldType()))) {
/* 103 */         if (!list.contains(this.entity.getPackageName() + ".base." + "AttachFile")) {
/* 104 */           list.add(this.entity.getPackageName() + ".base." + "AttachFile");
/*     */         }
/* 106 */         if (!list.contains(this.entity.getPackageName() + ".base.AttachFilePropertyEditor")) {
/* 107 */           list.add(this.entity.getPackageName() + ".base.AttachFilePropertyEditor");
/*     */         }
/*     */       }
/*     */     }
/*     */ 
/* 112 */     return list;
/*     */   }
/*     */ 
/*     */   public List<String> getImportDeclarations() {
/* 116 */     List list = new ArrayList();
/* 117 */     list.addAll(getImportClassNameList());
/*     */ 
/* 119 */     return ConventionUtils.getImportDeclarations(list, getFullPackageName());
/*     */   }
/*     */ 
/*     */   public String getParseRequestParameterSnippet() {
/* 123 */     return getParseRequestParameterSnippet("\t\t\t");
/*     */   }
/*     */ 
/*     */   public String getParseRequestParameterSnippet(String indent) {
/* 127 */     StringBuffer buffer = new StringBuffer();
/*     */ 
/* 129 */     for (Field field : this.entity.getPrimaryKeyFieldList()) {
/* 130 */       if (field.getFieldType().equals("char")) {
/* 131 */         buffer.append(indent + "// FIXME: Entity generator." + FileUtils.ln());
/* 132 */         buffer.append(indent + field.getFieldType() + " " + field.getFieldName() + " = " + "'';" + FileUtils.ln());
/* 133 */       } else if ((field.isPrimitiveType()) || (String.class.getName().equals(field.getFieldType()))) {
/* 134 */         buffer.append(indent + field.getSimpleFieldType() + " " + field.getFieldName() + " = " + "ServletRequestUtils.getRequired" + firstCharacterUpperCaseConverter.convert(field.getSimpleFieldType()) + "Parameter(request, \"" + field.getFieldName() + "\");" + FileUtils.ln());
/*     */       } else {
/* 136 */         buffer.append(indent + "// FIXME: Entity generator." + FileUtils.ln());
/* 137 */         buffer.append(indent + field.getSimpleFieldType() + " " + field.getFieldName() + " = " + "null;" + FileUtils.ln());
/*     */       }
/*     */     }
/*     */ 
/* 141 */     return buffer.toString();
/*     */   }
/*     */ 
/*     */   public boolean isCustomDateEditorRequired() {
/* 145 */     for (Field field : this.entity.getFieldList()) {
/* 146 */       if ((field.isCreate()) && (Date.class.getName().equals(field.getFieldType()))) {
/* 147 */         return true;
/*     */       }
/*     */     }
/*     */ 
/* 151 */     return false;
/*     */   }
/*     */ 
/*     */   public boolean isOnBindRequired() {
/* 155 */     return isAttachFilePropertyEditorRequired();
/*     */   }
/*     */ 
/*     */   public boolean isAttachFilePropertyEditorRequired() {
/* 159 */     for (Field field : this.entity.getFieldList()) {
/* 160 */       if ((field.isCreate()) && ("AttachFile".equals(field.getFieldType()))) {
/* 161 */         return true;
/*     */       }
/*     */     }
/*     */ 
/* 165 */     return false;
/*     */   }
/*     */ 
/*     */   public String getInitBinderCustomDateEditor() {
/* 169 */     return getInitBinderCustomDateEditor("\t\t");
/*     */   }
/*     */ 
/*     */   public String getInitBinderCustomDateEditor(String indent) {
/* 173 */     StringBuffer buffer = new StringBuffer();
/*     */ 
/* 175 */     boolean first = true;
/* 176 */     for (Field field : this.entity.getFieldList()) {
/* 177 */       if ((field.isCreate()) && (Date.class.getName().equals(field.getFieldType()))) {
/* 178 */         if (!first) {
/* 179 */           buffer.append(FileUtils.ln());
/*     */         }
/* 181 */         buffer.append(indent + "binder.registerCustomEditor(Date.class, \"" + field.getFieldName() + "\", new CustomDateEditor(new SimpleDateFormat(\"yyyyMMdd\"), false, 8));");
/* 182 */         first = false;
/*     */       }
/*     */     }
/*     */ 
/* 186 */     return buffer.toString();
/*     */   }
/*     */ 
/*     */   public String getInitBinderAttachFilePropertyEditor() {
/* 190 */     return getInitBinderAttachFilePropertyEditor("\t\t");
/*     */   }
/*     */ 
/*     */   public String getInitBinderAttachFilePropertyEditor(String indent) {
/* 194 */     StringBuffer buffer = new StringBuffer();
/*     */ 
/* 196 */     boolean first = true;
/* 197 */     for (Field field : this.entity.getFieldList()) {
/* 198 */       if ((field.isCreate()) && ("AttachFile".equals(field.getFieldType()))) {
/* 199 */         if (!first) {
/* 200 */           buffer.append(FileUtils.ln());
/*     */         }
/* 202 */         buffer.append(indent + "binder.registerCustomEditor(AttachFile.class, \"" + field.getFieldName() + "\", new AttachFilePropertyEditor());");
/* 203 */         first = false;
/*     */       }
/*     */     }
/*     */ 
/* 207 */     return buffer.toString();
/*     */   }
/*     */ 
/*     */   public Entity getEntity() {
/* 211 */     return this.entity;
/*     */   }
/*     */ 
/*     */   public void setEntity(Entity entity) {
/* 215 */     this.entity = entity;
/*     */   }
/*     */ }

/* Location:           C:\Users\lzl6066\Downloads\net.sourceforge.appgen_1.2.0\plugins\net.sourceforge.appgen_1.2.0.201002031718\
 * Qualified Name:     net.sourceforge.appgen.model.FormController
 * JD-Core Version:    0.6.0
 */